package com.toKnow.service.impl;

import com.toKnow.mapper.ColumnPubDao;
import com.toKnow.mapper.ColumnTagPubDao;
import com.toKnow.mapper.ColumnTypePubDao;
import com.toKnow.mapper.UserInfoPubDao;
import com.toKnow.model.entity.*;
import com.toKnow.service.ColumnPubService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service("columnPubService")
public class ColumnPubServiceImpl implements ColumnPubService {


    @Autowired
    private ColumnPubDao columnPubDao;
    @Autowired
    private ColumnTagPubDao columnTagPubDao;
    @Autowired
    private ColumnTypePubDao columnTypePubDao;
    @Autowired
    private UserInfoPubDao userInfoPubDao;

    public void setColumnPubDao(ColumnPubDao columnPubDao) {
        this.columnPubDao = columnPubDao;
    }

    public void setColumnTagPubDao(ColumnTagPubDao columnTagPubDao) {
        this.columnTagPubDao = columnTagPubDao;
    }

    public void setColumnTypePubDao(ColumnTypePubDao columnTypePubDao) {
        this.columnTypePubDao = columnTypePubDao;
    }

    public void setUserInfoPubDao(UserInfoPubDao userInfoPubDao) {
        this.userInfoPubDao = userInfoPubDao;
    }

    @Override
    @Transactional
    public int addColumn(ColumnPub columnPub,  UserInfoPub userInfoPub) {

        //System.out.println("service");

        int row1 = columnPubDao.insertColumn(columnPub);
        //System.out.println("row1 = " + row1);


        int row2 = userInfoPubDao.updateColumnNum(userInfoPub);
        //System.out.println("row2 = " + row2);


        return (row1&row2);
    }

    @Override
    @Transactional
    public Integer addColumnReturnId(ColumnPub columnPub, UserInfoPub userInfoPub) {

        int row1 = columnPubDao.insertColumnReturnId(columnPub);

        int row2 = userInfoPubDao.updateColumnNum(userInfoPub);

        Integer column_id = columnPub.getId();

        return column_id ;
    }

    @Override
    @Transactional
    public int addType(ColumnTypePub columnTypePub) {

        int row1 = columnTypePubDao.insertColumnType(columnTypePub);

        return row1;
    }

    @Override
    @Transactional
    public int addTag(ColumnTagPub columnTagPub) {

        int row1 = columnTagPubDao.insertColumnTag(columnTagPub);

        return row1;
    }
}
